package ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name="Fresitaws", serviceName="Fresitaws", portName="FresitaPort",targetNamespace = "http://fresita/")
@SOAPBinding(style=SOAPBinding.Style.RPC)
public class RecipeServer extends P2PServer{
    private fresita.Controller controller;
    /** Creates a new instance of RecipeServer */
    public RecipeServer(MachineList machineList, fresita.Controller controller) {
        super( machineList );
        this.controller = controller;
    }
    
    @WebMethod(operationName="getRecipe")
    public String getRecipe(String fileName)
    {
        model.Recipe recipe = controller.getRecipe(fileName);
        return (recipe == null)?"":recipe.toXmlString();
    }
    
    @WebMethod(operationName="getIngredient")
    public String getIngredient(String fileName)
    {
        model.Ingredient ingredient = controller.getIngredient(fileName);
        return (ingredient == null)?"":ingredient.toXmlString();
    }
    
    @WebMethod(operationName="addIngredient")
    public boolean addIngredient(String xml)
    {
        model.Ingredient ingredient = model.Ingredient.fromXml(xml);
        if(ingredient == null)
            return false;
        
        return controller.addIngredient(ingredient);
    }
    
    @WebMethod(operationName="addRecipe")
    public boolean addRecipe(String xml)
    {
        model.Recipe recipe = model.Recipe.fromXml(xml);
        if(recipe == null)
            return false;
        
        return controller.addRecipe(recipe);
    }
}
